package com.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pojo.Comment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CommentDao extends BaseMapper<Comment> {

@Insert("insert into commented_info values(null, #{content}, #{username} ,#{pid},#{target},0,#{createtime},#{avatarUrl},#{imgUrl})")
    int addComment(Comment comment);
//查询所有
    @Select("select * from commented_info")
List<Comment> findAll();
//删除主评论
@Delete("delete from commented_info where c_id=#{cId} or pid=#{cId}")
int deleteComment(Integer cId);
//删除子评论
@Delete("delete from commented_info where  pid=#{cId}")
int deletechildrenComment(Integer cId);

@Update("update commented_info set like_num=like_num+1 where c_id=#{cId}")
int addLikeNum(Integer cId);

    @Update("update commented_info set like_num=like_num-1 where c_id=#{cId}")
    int redLikeNum(Integer cId);
//查询所有的主评论
    @Select("select * from commented_info where ISNULL(pid)")
    List<Comment> findPidNull();

//    查询用户所有的子评论
@Select("select * from commented_info where pid is not null and username=#{username} ")
List<Comment> findpidNullByUsername(String username);

//    查询用户所有的主评论
@Select("select * from commented_info where ISNULL(pid) and username=#{username}")
    List<Comment> findByPageByUsername(String username);

    //    根据名字查找对应id
    @Select("select  id from sys_user where username=#{username}")
  int  findIdByUsername( String username);
}
